<template>
    <div
        v-loading="loading"
        :element-loading-svg="$config.svg"
        element-loading-svg-view-box="-10, -10, 50, 50"
        :element-loading-text="$t('Base.test')"
        class="h100"
    >
        <router-view v-if="isReload" />
    </div>
</template>

<script setup lang="ts">
import { provide, nextTick, ref, onMounted, onBeforeUnmount } from 'vue';
import $config from '@/config';
import { loading } from '@/utils/loading';
import { setAppRem } from '@/utils/pxtorem';
import { errorTips, setStore } from '@/utils/utils';
import { useUserStore } from '@/stores/user';
const userStore = useUserStore();
const isReload = ref(true);

onMounted(() => {
    setAppRem();
});

provide('reload', () => {
    isReload.value = false;
    nextTick(() => {
        isReload.value = true;
    });
});

// 获取app信息
const getAppConfig = async () => {
    try {
        const config: any = await _bridge.callNative('getAppConfig');
        console.log(config, 'getAppConfig');
        setStore($config.CONFIG, config);

        const userInfo: any = await _bridge.callNative('getAppUserInfo');
        console.log(userInfo, 'getAppUserInfo');

        userStore.setUserInfo(userInfo);
        userStore.setToken(userInfo.token);
    } catch (error) {
        errorTips('get appInfo error');
    }
};

getAppConfig();
</script>

<style scoped lang="scss"></style>
